﻿@using Sharp.Infrastructure
@using Sharp.Portal.Configuration

@{
    var config = SystemConfigManage.Read<PlatformInfo>();
    var x = Html.X();

    #region 动态加载订阅项

    var portalPanel = x.Portal().Title("桌面").HideMode(HideMode.Offsets).Icon(Icon.Application);

    //if (WebServer.IsMobileDevice())
    //{
    //    config.PortalColumnNum = 1;
    //}
    for (var i = 0; i < config.PortalColumnNum; i++)
    {
        portalPanel.Items().Add(x.PortalColumn());
    }

    //var panelRule = new ResponsiveRule()
    //{
    //    Rule = "width<=1024"
    //};
    //panelRule.Config.Add(x.Portal().Items);
    //portalPanel.ResponsiveConfig(rc =>
    //{
    //    rc.Add(panelRule);
    //});

    Queue<string> subscriber = new Queue<string>();

    var files = new DirectoryInfo(Server.MapPath("~/Areas/Platform/Views/Home/Subscriber")).GetFiles("*.cshtml").Select(f => f.Name.Substring(0, f.Name.IndexOf(".cshtml", StringComparison.Ordinal)));

    foreach (var f in files)
    {
        subscriber.Enqueue("Subscriber/" + f);
    }

    while (subscriber.Count > 0)
    {
        //portalPanel.Items(x.Component().ContentFromPartial(subscriber.Dequeue()));
        foreach (var abstractComponent in portalPanel.ToComponent().LazyItems)
        {
            var pc = (PortalColumn)abstractComponent;
            pc.Items.Add(x.Component().LazyMode(LazyMode.Instance).ContentFromPartial(subscriber.Dequeue()));
            if (subscriber.Count == 0)
            {
                break;
            }
        }
    }
    #endregion
}
@(
    x.TabPanel()
        .ID("ExampleTabs")
        .Region(Region.Center)
        .MinTabWidth(110)
        .Items(items => items.Add(portalPanel))
        .ResponsiveConfig(rr =>
        {
            var tabsRule = new ResponsiveRule()
            {
                Rule = "width<=1024"
            };
            tabsRule.Config.Add(x.TabPanel().MinTabWidth(48));
            rr.Add(tabsRule);
        })
        .Listeners(l => { l.TabChange.Fn = "App.Main.addToken"; })
        .Plugins(plugins => plugins.Add(new TabCloseMenu()
        {
            CloseOthersTabsText = "关闭其他",
            CloseAllTabsText = "关闭全部",
            CloseTabText = "关闭"
        }))      
    )